
             
/**
 * Copyright (c) 2012-2013 JLLT Corp. 2012-2013,All Rights Reserved.
 * This software is published under the 金麟龙腾商贸有限公司.
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 *
 * @File name:  TOrderDao.java 
 * @Create on:  2012-10-25 09:53:644
 * @Author   :  陈伟
 *
 * @ChangeList
 * ---------------------------------------------------
 * Date         Editor              ChangeReasons
 *
 */
           
package com.boho.ecp.manage.order.dao;

            
import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.Pager;
            
        /**
 * 【订单信息:T_ORDER】的Dao操作类
 * 
 */
public class TOrderDao extends DAO {
	/**
	* 查询所有【订单信息:T_ORDER】信息
	* @param con
	* @return
	* @throws Exception
	* @date 2012-10-25
	* @author 陈伟
	*
	*/
	public static List queryTOrder(Connection con)throws Exception{
		List list = new LinkedList();
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_ORDER");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		list = query.getDynaBeanMapList("T_ORDER", con);
		return list;
	}
	/**
	* 分页查询所有【订单信息:T_ORDER】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2012-10-25
	* @author 陈伟
	*
	*/
	public static ComboPager queryTOrderByPager(Connection con,Pager pager, String orderId, Integer status)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_ORDER  where IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int i = 0;
		if(StringUtils.isNotEmpty(orderId)){
			sql.append(" and ORDER_ID = ?");
			query.setString(++i, orderId);
		}
		if(status != 0){
			sql.append(" and STATUS = ?");
			query.setInt(++i, status);
		}
		sql.append(" order by ORDER_DATE desc");
		query.setCommand(sql.toString());
		return query.getDynaBeanMapComboPager("T_ORDER", pager,con);
	}
	/**
	* 根据主键【订单编号:ORDER_ID|】获得信息
	* @param con
	* @param orderId 订单编号
	* @return
	* @throws Exception
	* @date 2012-10-25
	* @author 陈伟
	*
	*/
	public static DynaBeanMap getTOrderByPk(Connection con, String orderId)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_ORDER where IS_VALID = 1 and ORDER_ID=?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1,orderId);
		dynaBeanMap = query.getDynaBeanMap("T_ORDER", con);
		return dynaBeanMap;
	}
	
	/**
	 * 根据ID查询订单详细信息
	 * @param con
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	public static List getOrderDetailById(Connection con, String id) throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_ORDER_DETAIL where IS_VALID = 1 and ORDER_ID = ?");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, id);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_ORDER_DETAIL", con);
	}
	
	/**
	 * 根据订单ID查询订单状态变更历史
	 * @param con
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public static List queryOrderLogList(Connection con, String id) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_ORDER_CHANGE_LOG where IS_VALID = 1 and ORDER_ID = ? order by CHANGE_DATE");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, id);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_ORDER_CHANGE_LOG", con);
	}
	
	/**
	* 查询会员收获地址信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2012-10-09
	* @author 陈伟
	*
	*/
	public static DynaBeanMap getTDeliveryAddressByPk(Connection con,java.lang.Integer deliveryAddressId)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DELIVERY_ADDRESS where DELIVERY_ADDRESS_ID = ? and IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,deliveryAddressId);
		dynaBeanMap = query.getDynaBeanMap("T_DELIVERY_ADDRESS", con);
		return dynaBeanMap;
	}
	
	/**
	 * 查询配送单
	 * @param con
	 * @param orderId
	 * @return
	 * @throws Exception
	 */
	public static DynaBeanMap getDeliverOrder(Connection con, String orderId) throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DELIVER_ORDER where ORDER_ID = ? and IS_VALID = 1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1,orderId);
		dynaBeanMap = query.getDynaBeanMap("T_DELIVER_ORDER", con);
		return dynaBeanMap;
	}
	
	/**
	 * 查询配送商品列表
	 * @param con
	 * @param orderId
	 * @return
	 * @throws Exception
	 */
	public static List queryDeliverDetailList(Connection con, String orderId) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_DELIVER_DETAIL where IS_VALID = 1 and ORDER_ID = ? order by PRODUCT_ID");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setString(1, orderId);
		query.setCommand(sql.toString());
		return query.getDynaBeanMapList("T_DELIVER_DETAIL", con);
	}
}
